#ifndef DEVICEOBJECT
#define DEVICEOBJECT
#include <cuda_runtime.h>
#include "global_object.h"
   /**
    * This class provides functionality for transferring objects to and from the device.
	* It implements a shallow copy of the object's members. Any complex objects should
	* override these to also operate on any pointer members.
	*/

class DeviceObject
{
public:
	inline __host__ __device__   DeviceObject(){
		d_address = NULL;
		size = sizeof(DeviceObject);
	}
	inline virtual __host__ __device__  ~DeviceObject(){}
	inline virtual __host__ void copyToDevice(){
		if(d_address == NULL){
			cudaMalloc(&d_address, size);
		}
		cudaMemcpy(d_address, this, size, cudaMemcpyHostToDevice);
	}

	inline virtual __host__ void updateFromDevice()	{
		if(d_address != NULL){
			cudaMemcpy(this, d_address, size, cudaMemcpyDeviceToHost);
		}
	}

	inline virtual __host__ void deleteFromDevice(){
		if(d_address != NULL){
			cudaFree(d_address);
			d_address = NULL;
		}
	}

	void* d_address;
	size_t size;
};

#endif

